/*
 * DiskManager.h
 *
 *  Created on: 14-Oct-2013
 *      Author: pridhvi
 */

#ifndef DISKMANAGER_H_
#define DISKMANAGER_H_
#include "../Global/BaseEntity.h"
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
#include "../dependency/debug.h"
#include "../Global/GlobalVar.h"
#include "../BufferManager/BufferUtility.h"
#include "../Global/StructureHeaders.h"
using namespace std;

class DiskManager : virtual BaseEntity {
   
public:
     int _fd;
    DiskManager();
    virtual ~DiskManager();

    /************************************ DATABASE FUNCTION CALLS START*********************************/
    /***
     * used for creating the database and writing initial structures of systable,DBHeader,freeLinkedList etc
     * here only authorization is given
     */
    STATUS_CODE createDataBase(string dbName, int noOfPages);

    STATUS_CODE openDataBase(string dbName);

    STATUS_CODE closeDataBase();


    STATUS_CODE dropDataBase(string dbName);

    STATUS_CODE resizeDataBase(int noOfPages);
    STATUS_CODE expandDataBase(int noOfPages);

    STATUS_CODE readPage(int pageSize, char *pageData, int pageNo);
    STATUS_CODE readPage(int cache_id, int pageSize, char *pageData, int pageNo);

    STATUS_CODE writePage(int pageSize, char *pageData, int pageNo);
    STATUS_CODE writePage(int cache_id, int pageSize, char *pageData, int pageNo);

    bool IsDBExists(string dbName);

    int getFreeCacheIndex();

    void initCacheIndex();

    STATUS_CODE displayCacheIndex();

    map<string, int> listDB();

    STATUS_CODE closeDataBase(int cache_id);
};

#endif /* DISKMANAGER_H_ */
